Fix delete/xfree mismatch in xmltag copy
authorRobert Lipe <robertlipe@gpsbabel.org>
Thu, 5 Jul 2018 03:53:22 +0000 (22:53 -0500)
committerRobert Lipe <robertlipe@gpsbabel.org>
Thu, 5 Jul 2018 03:53:22 +0000 (22:53 -0500)
Other misc minor changes tweaks identified by codacy during last commit.

arcdist.cc
lowranceusr4.cc
mtk_logger.cc
psitrex.cc
tpo.cc
xmltag.cc

index ac97fb8ddcc671c945bf436d2a865f24b4729f09..9174f4b03aeb99347706a312f156745eba032998 100644 (file)
@@ -47,7 +47,7 @@ void ArcDistanceFilter::arcdist_arc_disp_wpt_cb(const Waypoint* arcpt2)
 #else
     queue* elem, * tmp;
     QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-      Waypoint *  waypointp = (Waypoint*) elem;
+      Waypoint* waypointp = (Waypoint*) elem;
 #endif
       double dist;
       extra_data* ed;
index efd1d5e357c6dd334cd0812b88bc4c2ae456f95d..7670042b94e2dd3bed0232366cba8e5de9dc7ded 100644 (file)
@@ -349,7 +349,6 @@ lowranceusr4_parse_waypoints()
 {
   short int icon_num;
   unsigned int i, num_waypts, create_date, create_time;
-  int text_len;
   char buff[MAXUSRSTRINGSIZE + 1];
 
   num_waypts = gbfgetint32(file_in);
@@ -401,7 +400,7 @@ lowranceusr4_parse_waypoints()
     gbfgetint16(file_in);
 
     /* Waypoint name; input is 2 bytes per char, we convert to 1 */
-    text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
+    int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
       wpt_tmp->shortname = buff;
@@ -585,7 +584,7 @@ lowranceusr4_parse_routes()
 static void
 lowranceusr4_parse_trails()
 {
-  int num_trails, M, i, j, k, trk_num, text_len;
+  int num_trails, M, i, j, k, trk_num;
   char buff[MAXUSRSTRINGSIZE + 1];
   Waypoint* wpt_tmp;
 
@@ -649,7 +648,7 @@ lowranceusr4_parse_trails()
     gbfgetint16(file_in);
 
     /* Trail name; input is 2 bytes per char, we convert to 1 */
-    text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
+    int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
       trk_head->rte_name = buff;
index f5c53b4f7017e725df915646e6a520da928527d2..7ac78988670624a10b74fff0604831861b5c07aa 100644 (file)
@@ -499,7 +499,7 @@ static void mtk_rd_deinit()
 
 static int mtk_erase()
 {
-  int log_status, err;
+  int log_status;
   char* lstatus = nullptr;
 
   log_status = 0;
@@ -529,8 +529,8 @@ static int mtk_erase()
   gb_sleep(100*1000);
 
   if ((log_status & 2)) {  // auto-log were enabled before..re-enable log.
-    err = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2);
-    dbg(3, "re-enable log %s\n", err==0?"Success":"Fail");
+    int err = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2);
+    dbg(3, "re-enable log %s\n", err == 0 ? "Success" : "Fail");
   }
   return 0;
 }
index 6115726268a794bb64aa787516a0367b64e46737..eed700e28fbdfc1786b05319b7d86383c6ce2660 100644 (file)
@@ -459,12 +459,11 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte)
   Waypoint* testwpt;
 
   /* total nodes (waypoints) this route */
-  unsigned int rte_datapoints = 0;
   if (rte->waypoint_list.next) { 
     // this test doesn't do what I w ant i.e test if this is a valid 
     // route - treat as a placeholder for now .
     time_t uniqueValue = 0;
+    unsigned int rte_datapoints = 0;
     queue *elem, *tmp;
     QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
       testwpt = (Waypoint*)elem;
@@ -608,9 +607,9 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk)
 
   if (psit_track_state == 2) {
     /* total nodes (waypoints) this track */
-    unsigned int trk_datapoints = 0;
     if (trk->waypoint_list.next) {     /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
 
+      unsigned int trk_datapoints = 0;
       QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
         if (trk_datapoints == 0) {
           Waypoint* testwpt = (Waypoint*)elem;
diff --git a/tpo.cc b/tpo.cc
index 38a697a0c2f78625c29fb8b67d507e9e4d1bbcef..f3896490b01069049f2fae5a5dc38f1d952203e9 100644 (file)
--- a/tpo.cc
+++ b/tpo.cc
@@ -259,8 +259,6 @@ static void tpo_read_2_x()
 {
   char buff[16];
   short track_count, waypoint_count;
-  double lat_scale, lon_scale, amt;
-  int i, j;
 
   /* track count */
   track_count = gbfgetint16(tpo_file_in);
@@ -273,7 +271,7 @@ static void tpo_read_2_x()
   /* chunk name: "CTopoRoute" */
   gbfread(&buff[0], 1, 12, tpo_file_in);
 
-  for (i=0; i<track_count; i++) {
+  for (int i = 0; i < track_count; i++) {
 
     route_head* track_temp = route_head_alloc();
     track_add_head(track_temp);
@@ -313,7 +311,7 @@ static void tpo_read_2_x()
     std::vector<short> lat_delta(waypoint_count);
     std::vector<short> lon_delta(waypoint_count);
 
-    for (j = 0; j < waypoint_count; j++) {
+    for (int j = 0; j < waypoint_count; j++) {
 
       /* get this point's longitude delta from the first waypoint */
       lon_delta[j] = gbfgetint16(tpo_file_in);
@@ -323,10 +321,10 @@ static void tpo_read_2_x()
     }
 
     /* 8 bytes - longitude delta to degrees scale  */
-    lon_scale = gbfgetdbl(tpo_file_in);
+    double lon_scale = gbfgetdbl(tpo_file_in);
 
     /* 8 bytes - latitude delta to degrees scale */
-    lat_scale = gbfgetdbl(tpo_file_in);
+    double lat_scale = gbfgetdbl(tpo_file_in);
 
     /* 4 bytes: the total length of the route in feet*/
     gbfread(&buff[0], 1, 4, tpo_file_in);
@@ -338,14 +336,14 @@ static void tpo_read_2_x()
     gbfread(&buff[0], 1, 2, tpo_file_in);
 
     /* multiply all the deltas by the scaling factors to determine the waypoint positions */
-    for (j = 0; j < waypoint_count; j++) {
+    for (int j = 0; j < waypoint_count; j++) {
 
       Waypoint* waypoint_temp = new Waypoint;
-
+      double amt;
       /* convert incoming NAD27/CONUS coordinates to WGS84 */
       GPS_Math_Known_Datum_To_WGS84_M(
-        first_lat-lat_delta[j]*lat_scale,
-        first_lon+lon_delta[j]*lon_scale,
+        first_lat-lat_delta[j] * lat_scale,
+        first_lon+lon_delta[j] * lon_scale,
         0.0,
         &waypoint_temp->latitude,
         &waypoint_temp->longitude,
@@ -489,7 +487,7 @@ static Waypoint* tpo_convert_ll(int lat, int lon)
   return(waypoint_temp);
 }
 
-#define TRACKNAMELENGTH 256
+#define TRACKNAMELENGTH 255
 class StyleInfo {
 public:
   QString name;
@@ -504,8 +502,6 @@ public:
 static void tpo_process_tracks()
 {
   unsigned int track_count, track_style_count;
-  unsigned int tmp;
-
   const int DEBUG = 0;
 
   if (DEBUG) {
@@ -544,11 +540,11 @@ static void tpo_process_tracks()
       styles[ii].color[xx] = (uint8_t)col;
     }
 
-    tmp = (unsigned char) gbfgetc(tpo_file_in);
+    unsigned char tmp = gbfgetc(tpo_file_in);
     // printf("Skipping unknown byte 0x%x after color\n",tmp);
 
     // byte for name length, then name
-    tmp = (unsigned char) gbfgetc(tpo_file_in);
+    tmp = gbfgetc(tpo_file_in);
     // wrong byte order?? tmp = tpo_read_int(); // 16 bit value
     // printf("Track %d has %d-byte (0x%x) name\n", ii, tmp, tmp);
     if (tmp >= TRACKNAMELENGTH) {
@@ -578,12 +574,12 @@ static void tpo_process_tracks()
 
     // clumsy way to skip two undefined bytes
     for (unsigned xx = 0; xx < 2; xx++) {
-      tmp = (unsigned char) gbfgetc(tpo_file_in);
-      // printf("Skipping final byte 0x%x\n",tmp);
+      tmp = gbfgetc(tpo_file_in);
+      // printf("Skipping final byte 0x%x\n", tmp);
     }
 
     if (DEBUG) {
-      printf("Track style %d: color=#%02x%02x%02x, width=%d, dashed=%d, name=%s\n",
+      printf("Track style %u: color=#%02x%02x%02x, width=%d, dashed=%d, name=%s\n",
              ii, styles[ii].color[0], styles[ii].color[1], styles[ii].color[2],
              styles[ii].wide, styles[ii].dash, qPrintable(styles[ii].name));
     }
index a9bce478c07fe32674c50dc2912b34810583d335..605b92eb6f9b075c7e8cff9555d34bbcd7494893 100644 (file)
--- a/xmltag.cc
+++ b/xmltag.cc
@@ -122,7 +122,7 @@ fs_xml_destroy(void* fs)
   if (xml) {
     free_xml_tag(xml->tag);
   }
-  xfree(fs);
+  delete xml;
 }
 
 static void